﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace CoolCode.UnitTest
{
    /// <summary>
    /// Windows版本
    /// </summary>
    public enum WindowsVersion
    {
        Unknown,
        Win95,
        Win98,
        WinMe,
        Win2000,
        WinXp,
        Win2003,
        Vista,
        Win2008,
        Win7,
        Future
    }

    /// <summary>
    /// Windows信息
    /// </summary>
    public class WindowsInformation
    {
        public static WindowsVersion GetVersion()
        {
            //Windows操作系统版本号组成部分:主版本号.次版本号.内部版本号.修订版本号
            WindowsVersion osVersion = WindowsVersion.Unknown;
            //从System引用空间中获取当前Windows操作系统的详细描述信息 
            OperatingSystem os = Environment.OSVersion;
            //从描述信息的版本号判断当前Windows操作系统平台. 
            switch (os.Platform)
            {
                //操作平台可能是Windows 95, Windows 98,Windows 98 Second Edition 或者 Windows Me. 
                case PlatformID.Win32Windows:
                    switch (os.Version.Minor)
                    {
                        case 0:
                            osVersion = WindowsVersion.Win95;
                            break;
                        case 10:
                            osVersion = WindowsVersion.Win98;
                            break;
                        case 90:
                            osVersion = WindowsVersion.WinMe;
                            break;
                        default:
                            osVersion = WindowsVersion.Unknown;
                            break;
                    } 
                    break;
                //操作平台可能是Windows NT 3.51, Windows NT 4.0, Windows 2000 或者 Windows XP. 
                case System.PlatformID.Win32NT:
                    switch (os.Version.Major)
                    {
                        //case 3:
                        //    osVersion = "Windows NT 3.51";
                        //    break;
                        //case 4:
                        //    osVersion = "Windows NT 4.0";
                        //    break;
                        case 5:
                            switch (os.Version.Minor)
                            {
                                case 0:
                                    osVersion = WindowsVersion.Win2000;
                                    break;
                                case 1:
                                    osVersion = WindowsVersion.WinXp;
                                    break;
                                case 2:
                                    osVersion = WindowsVersion.Win2003;
                                    break;
                                default:
                                    osVersion = WindowsVersion.Unknown;
                                    break;
                            } 
                            break;
                        case 6:
                            switch (os.Version.Minor)
                            {
                                case 0:
                                    osVersion = WindowsVersion.Vista;
                                    break;
                                case 1:
                                    osVersion = WindowsVersion.Win7;
                                    break;
                            }
                            break; 
                        default:
                            if (os.Version.Major >= 7)
                                osVersion = WindowsVersion.Future;
                            break;
                    } 
                    break;

                default:
                    osVersion = WindowsVersion.Unknown;
                    break;
            }
            return osVersion;
        }
    }
}
